import 'package:flutter/material.dart';
import 'package:math2/pages/answer/answer_page.dart';
import 'package:math2/pages/formula/formula_page.dart';

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  PageController pageController = PageController(initialPage: 0);
  var pages = [const AnswerPage(), const FormulaPage()];
  int currentIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
        controller: pageController,
        itemBuilder: (BuildContext context, int index) {
          return pages[index];
        },
        itemCount: 2,
        onPageChanged: (index) {
          setState(() {
            if (currentIndex != index) {
              currentIndex = index;
            }
          });
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.question_answer),
            label: '解答',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.functions),
            label: '公式',
          ),
        ],
        currentIndex: currentIndex,
        onTap: (index) {
          pageController.animateToPage(
            index,
            duration: const Duration(
              microseconds: 300,
            ),
            curve: Curves.ease,
          );
        },
        type: BottomNavigationBarType.fixed,
      ),
    );
  }
}
